#include <drv_cfg.h>
#include <os_clock.h>
#include <stdio.h>
#include <shell.h>
#include <sensors/sensor.h>
static int sensor_humi_test(int argc, char *argv[])
{
    int  i;
    char sensor_name[24] ;
    struct os_sensor_data sensor_data;

    if (argc != 2)
    {
        os_kprintf("usage:sensor_humi_test <sensor_name>\r\n");
        return -1;
    }

    snprintf(sensor_name, sizeof(sensor_name) - 1, "humi_%s", argv[1]);

    os_device_t *sensor = os_device_find(sensor_name);
    OS_ASSERT(sensor != NULL);
    os_device_open(sensor);

    struct os_sensor_info sensor_info;
    os_device_control(sensor, OS_SENSOR_CTRL_GET_INFO, &sensor_info);

    for (i = 0; i < 10; i++)
    {
        os_device_read_nonblock(sensor, 0, &sensor_data, sizeof(struct os_sensor_data));

        if (sensor_info.unit == OS_SENSOR_UNIT_MPERMILLAGE)
        {
            os_kprintf("sensor humi (%d.%03d)\r\n", sensor_data.data.humi / 1000, sensor_data.data.humi % 1000);
        }
        else if (sensor_info.unit == OS_SENSOR_UNIT_PERMILLAGE)
        {
            os_kprintf("sensor humi (%d)\r\n", sensor_data.data.humi);
        }
        else
        {
            os_kprintf("invalid unit\r\n");
        }

        os_task_msleep(1000);
    }

    return 0;
}
SH_CMD_EXPORT(sensor_humi_test, sensor_humi_test, "sensor_humi_test");
